$PingUrl='baidu.com'
$ServerLastIp='20'
##############################################################
$LocalIp=''
$Interface=''
$Mac=''
$Server=''

foreach ($vpn in Get-VpnConnection){
    cmd /c 'rasdial /disconnect 1>nul'
}

if((Test-NetConnection $PingUrl -WarningAction SilentlyContinue -OutVariable PingTest).PingSucceeded -eq $true){
    $LocalIp = $PingTest.SourceAddress.IPAddress
    $Interface = $PingTest.InterfaceAlias
    $Mac = (Get-NetAdapter -Name $Interface).MacAddress

    $ArrIp = $LocalIp.Split('.')
    $Server = $ArrIp[0], $ArrIp[1], $ArrIp[2], $ServerLastIp -Join '.'
}

if((Test-NetConnection $Server -WarningAction SilentlyContinue).PingSucceeded -eq $true){
    if(![String]::IsNullOrEmpty($LocalIp) -and ![String]::IsNullOrEmpty($Mac)){
        $PostParams = @{mac=$Mac; ip=$LocalIp}
        $PostUrl = 'http://{0}/watchClient.php' -F $Server
        Invoke-WebRequest -Uri $PostUrl -Method Post -Body $PostParams
    }
}